home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / XFREE / common / compiler.h
Encoding:
C/C++ Source or Header  |  1995-10-29  |  8.2 KB  |  411 lines

  1. /* $XConsortium: compiler.h,v 1.2 94/10/12 20:33:21 kaleb Exp $ */
  2. /* $XFree86: xc/programs/Xserver/hw/xfree86/common/compiler.h,v 3.3 1995/01/28 17:03:15 dawes Exp $ */
  3. /*
  4.  * Copyright 1990,91 by Thomas Roell, Dinkelscherben, Germany.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and its
  7.  * documentation for any purpose is hereby granted without fee, provided that
  8.  * the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of Thomas Roell not be used in
  11.  * advertising or publicity pertaining to distribution of the software without
  12.  * specific, written prior permission.  Thomas Roell makes no representations
  13.  * about the suitability of this software for any purpose.  It is provided
  14.  * "as is" without express or implied warranty.
  15.  *
  16.  * THOMAS ROELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  17.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  18.  * EVENT SHALL THOMAS ROELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  19.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  20.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  21.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  22.  * PERFORMANCE OF THIS SOFTWARE.
  23.  *
  24.  */
  25.  
  26.  
  27. #ifndef _COMPILER_H
  28. #define _COMPILER_H
  29.  
  30. #ifndef __STDC__
  31. # ifdef signed
  32. #  undef signed
  33. # endif
  34. # ifdef volatile
  35. #  undef volatile
  36. # endif
  37. # ifdef const
  38. #  undef const
  39. # endif
  40. # define signed /**/
  41. # ifdef __GNUC__
  42. #  define volatile __volatile__
  43. #  define const __const__
  44. # else
  45. #  define const /**/
  46. # endif /* __GNUC__ */
  47. #endif /* !__STDC__ */
  48.  
  49. #ifdef NO_INLINE
  50.  
  51. extern void outb();
  52. extern void outw();
  53. extern void outl();
  54. extern unsigned int inb();
  55. extern unsigned int inw();
  56. extern unsigned int inl();
  57. #if NeedFunctionPrototypes
  58. extern unsigned char rdinx(unsigned short, unsigned char);
  59. extern void wrinx(unsigned short, unsigned char, unsigned char);
  60. extern void modinx(unsigned short, unsigned char, unsigned char, unsigned char);
  61. extern int testrg(unsigned short, unsigned char);
  62. extern int textinx2(unsigned short, unsigned char, unsigned char);
  63. extern int textinx(unsigned short, unsigned char);
  64. #else /* NeedFunctionProtoypes */
  65. extern unsigned char rdinx();
  66. extern void wrinx();
  67. extern void modinx();
  68. extern int testrg();
  69. extern int textinx2();
  70. extern int textinx();
  71. #endif /* NeedFunctionProtoypes */
  72.  
  73. #else /* NO_INLINE */
  74.  
  75. #ifdef __GNUC__
  76.  
  77. #if defined(__i386__)
  78.  
  79. #ifndef FAKEIT
  80. #ifdef GCCUSESGAS
  81.  
  82. /*
  83.  * If gcc uses gas rather than the native assembler, the syntax of these
  84.  * inlines has to be different.        DHD
  85.  */
  86.  
  87. static __inline__ void
  88. outb(port, val)
  89. short port;
  90. char val;
  91. {
  92.    __asm__ __volatile__("outb %0,%1" : :"a" (val), "d" (port));
  93. }
  94.  
  95.  
  96. static __inline__ void
  97. outw(port, val)
  98. short port;
  99. short val;
  100. {
  101.    __asm__ __volatile__("outw %0,%1" : :"a" (val), "d" (port));
  102. }
  103.  
  104. static __inline__ void
  105. outl(port, val)
  106. short port;
  107. int val;
  108. {
  109.    __asm__ __volatile__("outl %0,%1" : :"a" (val), "d" (port));
  110. }
  111.  
  112. static __inline__ unsigned int
  113. inb(port)
  114. short port;
  115. {
  116.    unsigned char ret;
  117.    __asm__ __volatile__("inb %1,%0" :
  118.        "=a" (ret) :
  119.        "d" (port));
  120.    return ret;
  121. }
  122.  
  123. static __inline__ unsigned int
  124. inw(port)
  125. short port;
  126. {
  127.    unsigned short ret;
  128.    __asm__ __volatile__("inw %1,%0" :
  129.        "=a" (ret) :
  130.        "d" (port));
  131.    return ret;
  132. }
  133.  
  134. static __inline__ unsigned int
  135. inl(port)
  136. short port;
  137. {
  138.    unsigned int ret;
  139.    __asm__ __volatile__("inl %1,%0" :
  140.        "=a" (ret) :
  141.        "d" (port));
  142.    return ret;
  143. }
  144.  
  145. #else    /* GCCUSESGAS */
  146.  
  147. static __inline__ void
  148. outb(port, val)
  149.      short port;
  150.      char val;
  151. {
  152.   __asm__ __volatile__("out%B0 (%1)" : :"a" (val), "d" (port));
  153. }
  154.  
  155. static __inline__ void
  156. outw(port, val)
  157.      short port;
  158.      short val;
  159. {
  160.   __asm__ __volatile__("out%W0 (%1)" : :"a" (val), "d" (port));
  161. }
  162.  
  163. static __inline__ void
  164. outl(port, val)
  165.      short port;
  166.      unsigned int val;
  167. {
  168.   __asm__ __volatile__("out%L0 (%1)" : :"a" (val), "d" (port));
  169. }
  170.  
  171. static __inline__ unsigned int
  172. inb(port)
  173.      short port;
  174. {
  175.   unsigned char ret;
  176.   __asm__ __volatile__("in%B0 (%1)" :
  177.            "=a" (ret) :
  178.            "d" (port));
  179.   return ret;
  180. }
  181.  
  182. static __inline__ unsigned int
  183. inw(port)
  184.      short port;
  185. {
  186.   unsigned short ret;
  187.   __asm__ __volatile__("in%W0 (%1)" :
  188.            "=a" (ret) :
  189.            "d" (port));
  190.   return ret;
  191. }
  192.  
  193. static __inline__ unsigned int
  194. inl(port)
  195.      short port;
  196. {
  197.   unsigned int ret;
  198.   __asm__ __volatile__("in%L0 (%1)" :
  199.                    "=a" (ret) :
  200.                    "d" (port));
  201.   return ret;
  202. }
  203.  
  204. #endif /* GCCUSESGAS */
  205.  
  206. #else /* FAKEIT */
  207.  
  208. static __inline__ void
  209. outb(port, val)
  210.      short port;
  211.      char val;
  212. {
  213. }
  214.  
  215. static __inline__ void
  216. outw(port, val)
  217.      short port;
  218.      short val;
  219. {
  220. }
  221.  
  222. static __inline__ void
  223. outl(port, val)
  224.      short port;
  225.      int val;
  226. {
  227. }
  228.  
  229. static __inline__ unsigned int
  230. inb(port)
  231.      short port;
  232. {
  233.   return 0;
  234. }
  235.  
  236. static __inline__ unsigned int
  237. inw(port)
  238.      short port;
  239. {
  240.   return 0;
  241. }
  242.  
  243. static __inline__ unsigned int
  244. inl(port)
  245.      short port;
  246. {
  247.   return 0;
  248. }
  249.  
  250. #endif /* FAKEIT */
  251.  
  252. #elif defined(__alpha__)
  253.  
  254. #define inb(p)        _inb((p))
  255. #define inw(p)        _inw((p))
  256. #define inl(p)        _inl((p))
  257. #define outb(p,v)    _outb((v),(p))
  258. #define outw(p,v)    _outw((v),(p))
  259. #define outl(p,v)    _outl((v),(p))
  260.  
  261. #endif
  262.  
  263. #else /* __GNUC__ */
  264. #if !defined(AMOEBA) && !defined(MINIX)
  265. # if defined(__STDC__) && (__STDC__ == 1)
  266. #  ifndef asm
  267. #   define asm __asm
  268. #  endif
  269. # endif
  270. # ifdef SVR4
  271. #  include <sys/types.h>
  272. #  ifndef __USLC__
  273. #   define __USLC__
  274. #  endif
  275. # endif
  276. # include <sys/inline.h>
  277. #endif
  278. #endif
  279.  
  280. /*
  281.  *-----------------------------------------------------------------------
  282.  * Port manipulation convenience functions
  283.  *-----------------------------------------------------------------------
  284.  */
  285.  
  286. #ifndef __GNUC__
  287. #define __inline__ /**/
  288. #endif
  289.  
  290. /*
  291.  * rdinx - read the indexed byte port 'port', index 'ind', and return its value
  292.  */
  293. static __inline__ unsigned char 
  294. #ifdef __STDC__
  295. rdinx(unsigned short port, unsigned char ind)
  296. #else
  297. rdinx(port, ind)
  298. unsigned short port;
  299. unsigned char ind;
  300. #endif
  301. {
  302.     if (port == 0x3C0)        /* reset attribute flip-flop */
  303.         (void) inb(0x3DA);
  304.     outb(port, ind);
  305.     return(inb(port+1));
  306. }
  307.  
  308. /*
  309.  * wrinx - write 'val' to port 'port', index 'ind'
  310.  */
  311. static __inline__ void 
  312. #ifdef __STDC__
  313. wrinx(unsigned short port, unsigned char ind, unsigned char val)
  314. #else
  315. wrinx(port, ind, val)
  316. unsigned short port;
  317. unsigned char ind, val;
  318. #endif
  319. {
  320.     outb(port, ind);
  321.     outb(port+1, val);
  322. }
  323.  
  324. /*
  325.  * modinx - in register 'port', index 'ind', set the bits in 'mask' as in 'new';
  326.  *        the other bits are unchanged.
  327.  */
  328. static __inline__ void
  329. #ifdef __STDC__
  330. modinx(unsigned short port, unsigned char ind, 
  331.        unsigned char mask, unsigned char new)
  332. #else
  333. modinx(port, ind, mask, new)
  334. unsigned short port;
  335. unsigned char ind, mask, new;
  336. #endif
  337. {
  338.     unsigned char tmp;
  339.  
  340.     tmp = (rdinx(port, ind) & ~mask) | (new & mask);
  341.     wrinx(port, ind, tmp);
  342. }
  343.  
  344. /*
  345.  * tstrg - returns true iff the bits in 'mask' of register 'port' are
  346.  *       readable & writable.
  347.  */
  348.  
  349. static __inline__ int
  350. #ifdef __STDC__
  351. testrg(unsigned short port, unsigned char mask)
  352. #else
  353. tstrg(port, mask)
  354. unsigned short port;
  355. unsigned char mask;
  356. #endif
  357. {
  358.     unsigned char old, new1, new2;
  359.  
  360.     old = inb(port);
  361.     outb(port, old & ~mask);
  362.     new1 = inb(port) & mask;
  363.     outb(port, old | mask);
  364.     new2 = inb(port) & mask;
  365.     outb(port, old);
  366.     return((new1 == 0) && (new2 == mask));
  367. }
  368.  
  369. /*
  370.  * testinx2 - returns true iff the bits in 'mask' of register 'port', index
  371.  *          'ind' are readable & writable.
  372.  */
  373. static __inline__ int
  374. #ifdef __STDC__
  375. testinx2(unsigned short port, unsigned char ind, unsigned char mask)
  376. #else
  377. testinx2(port, ind, mask)
  378. unsigned short port;
  379. unsigned char ind, mask;
  380. #endif
  381. {
  382.     unsigned char old, new1, new2;
  383.  
  384.     old = rdinx(port, ind);
  385.     wrinx(port, ind, old & ~mask);
  386.     new1 = rdinx(port, ind) & mask;
  387.     wrinx(port, ind, old | mask);
  388.     new2 = rdinx(port, ind) & mask;
  389.     wrinx(port, ind, old);
  390.     return((new1 == 0) && (new2 == mask));
  391. }
  392.  
  393. /*
  394.  * testinx - returns true iff all bits of register 'port', index 'ind' are 
  395.  *              readable & writable.
  396.  */
  397. static __inline__ int
  398. #ifdef __STDC__
  399. testinx(unsigned short port, unsigned char ind)
  400. #else
  401. testinx(port, ind, mask)
  402. unsigned short port;
  403. unsigned char ind;
  404. #endif
  405. {
  406.     return(testinx2(port, ind, 0xFF));
  407. }
  408.  
  409. #endif /* NO_INLINE */
  410. #endif /* _COMPILER_H */
  411.